package com.adwin.addcoin.ui.adapter

import android.content.Context
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.adwin.addcoin.R
import com.adwin.addcoin.repository.bean.CheckInBean
import com.adwin.addcoin.repository.bean.CheckInData
import com.adwin.addcoin.repository.bean.HomeTaskBean
import com.adwin.addcoin.ui.viewholder.CheckInHolder
import com.google.gson.Gson

class CheckInAdapter(val mContext:Context,private var checkList:List<CheckInData>) : Adapter<CheckInHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CheckInHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.task_check_in_item_view,parent,false)
        return CheckInHolder(view)
    }

    override fun getItemCount(): Int = checkList.size

    override fun onBindViewHolder(holder: CheckInHolder, position: Int) {
        val data = checkList[position]

        Log.d("TaskFragment","check:${Gson().toJson(checkList)}")

        holder.setCoin("${data.coins}")
        if (data.isCheckIn){
            holder.itemView.background.setTint(Color.parseColor("#CCCCCC"))
        }else{
            holder.itemView.background.setTint(Color.parseColor("#F0F7FF"))
        }
        holder.setDayText(data.dayTitle)
    }
}